package 力扣._8022_找出美丽数组的最小和;

public class Solution {
    public long minimumPossibleSum(int n, int target) {
        long[] nums = new long[n];
        nums[0]=1;
        long num = 2, sum = 1;
        for (int i = 1; i < n; num++) {
            boolean isok = true;
            //二分
            int l = 0, r = i, mid;
            while (l <= r) {
                mid = (l + r) / 2;
                if (num + nums[mid] == target) {
                    isok = false;
                    break;
                } else if (num + nums[mid] < target) {
                    l = mid + 1;
                } else
                    r = mid - 1;
            }
            if (isok) {
                nums[i++] = num;
                sum += num;
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        long l = new Solution().minimumPossibleSum(1, 1);
        System.out.println(l);
    }
}
